library(leaflet)
library(tidyverse)
library(rgdal)
library(stringr)
#Link to Community Areas Shape File:
#https://data.cityofchicago.org/Facilities-Geographic-Boundaries/Boundaries-Community-Areas-current-/cauq-8yn6
#Link to Nieghborhoods Shape File:
#https://data.cityofchicago.org/Facilities-Geographic-Boundaries/Boundaries-Neighborhoods/9wp7-iasj
#Link to libraries data set
#https://data.cityofchicago.org/Education/Libraries-Locations-Hours-and-Contact-Information/x8fc-8rcq/data
#Census Tracts:
#https://data.cityofchicago.org/Facilities-Geographic-Boundaries/Boundaries-Census-Tracts-2010/5jrd-6zik
#We want to seperate out these latitudes and longitudes to make it easier to use
clean_location <- function(location) {
cleaned <- stringr::str_replace(location, '\\(' ,"")
cleaned <-stringr::str_replace(cleaned, "\\)","")
#print(cleaned)
return(cleaned)
}
libraries$LOCATION<-sapply(libraries$LOCATION, clean_location)
libraries <-separate(libraries, LOCATION, c("lat","long"),",")
libraries$lat <- as.numeric(libraries$lat)
libraries$long <- as.numeric(libraries$long)
glimpse(libraries)
Observations: 80
Variables: 12
$ NAME <chr> "Albany Park", "Altgeld", "Archer Heights", "Austin", "Austin-I...
$ `HOURS OF OPERATION` <chr> "M, W: 10AM-6PM; TU, TH: 12PM-8PM; F, SA: 9AM-5PM; SU: Closed"...
$ CYBERNAVIGATOR <chr> "Yes", "Yes", "No", "Yes", "No", "Yes", "No", "No", "No", "Yes"...
$ `TEACHER IN THE LIBRARY` <chr> "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", ...
$ ADDRESS <chr> "3401 W. Foster Avenue", "13281 S. Corliss Avenue", "5055 S. Ar...
$ CITY <chr> "CHICAGO", "CHICAGO", "CHICAGO", "CHICAGO", "CHICAGO", "CHICAGO...
$ STATE <chr> "IL", "IL", "IL", "IL", "IL", "IL", "IL", "IL", "IL", "IL", "IL...
$ ZIP <int> 60625, 60827, 60632, 60644, 60634, 60617, 60609, 60643, 60640, ...
$ PHONE <chr> "(773) 539-5450", "(312) 747-3270", "(312) 747-9241", "(312) 74...
$ WEBSITE <chr> "https://www.chipublib.org/locations/3/", "https://www.chipubli...
$ lat <dbl> 41.97546, 41.65473, 41.80121, 41.88927, 41.95317, 41.74672, 41....
$ long <dbl> -87.71409, -87.60223, -87.72649, -87.76571, -87.77939, -87.5854...
addPolygons(color = “#444444”, weight = 1, smoothFactor = 0.5, opacity = 1.0, fillOpacity = 0.5, fillColor = ~colorQuantile(“YlOrRd”, ALAND)(ALAND), highlightOptions = highlightOptions(color = “white”, weight = 2, bringToFront = TRUE))
#Chicago Lat Long 41.881832, -87.623177.
m <- leaflet() %>%
addTiles() %>%
#addProviderTiles(providers$OpenMapSurfer.Grayscale) %>%
setView(lng = -87.623177,
lat =41.881832,
zoom = 10) %>%
addMarkers(~long,
~lat,
popup = ~NAME,
data = libraries,
group = "Libraries")%>%
addPolygons(data = community_areas,
weight = 1,
fillColor = "green",
fillOpacity = .25,
label = ~community,
group = "Community Areas") %>%
addPolygons(data = census_tracts,
group = 'Census Tracts',
label = ~geoid10,
fillColor = "red",
fillOpacity = .25,
weight = 1)%>%
addLayersControl(overlayGroups = c("Community Areas",
"Libraries",
"Census Tracts"))
m
sprintf(“ %s: : %s”, parent_name, lettergrade)
label <- sprintf("<strong>%s</strong>:
<br> %s <br>--------
<br> %s
<br> %s
<br> %s, %s
<br>--------
<br> %s
<br>
<a href = %s>website<a>",
libraries$NAME,
libraries$`HOURS OF OPERATION`,
libraries$ADDRESS,
libraries$CITY,
libraries$STATE,
libraries$ZIP,
libraries$PHONE,
libraries$WEBSITE)
?sprintf
m2 <- leaflet() %>%
addTiles() %>%
#addProviderTiles(providers$OpenMapSurfer.Grayscale) %>%
setView(lng = -87.623177,
lat =41.881832,
zoom = 10) %>%
addMarkers(~long,
~lat,
popup = label,
data = libraries,
group = "Libraries")%>%
addPolygons(data = community_areas,
weight = 1,
fillColor = "green",
fillOpacity = .25,
label = ~community,
group = "Community Areas") %>%
addPolygons(data = census_tracts,
group = 'Census Tracts',
label = ~geoid10,
fillColor = "red",
fillOpacity = .25,
weight = 1)%>%
addLayersControl(overlayGroups = c("Community Areas",
"Libraries",
"Census Tracts"))
m2